<!--
 * @Date: 2024-12-25 19:45:43
 * @LastEditors: Lcx l1556461835@163.com
 * @LastEditTime: 2025-03-20 19:06:28
 * @FilePath: \simulation-fontend\pages\components\LCS.vue
 * @Description:
-->
<template>
  <div>
    <el-card header="PDI参数">
      <el-form :inline="true" :model="tbProcalcSumDTO" label-position="left" label-width="120px">
        <el-form-item label="钢种" prop="steelGrade">
          <el-select v-model="tbProcalcSumDTO.steelGrade" placeholder="钢种" @change="handleSteelChange">
            <el-option v-for="item in steelList" :key="item.id" :label="item.steelGrade" :value="item.steelGrade"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="板坯长度[mm]" prop="en_len">
          <el-input v-model="tbProcalcSumDTO.en_len" placeholder="板坯长度" @input="(v)=>(tbProcalcSumDTO['en_len'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="板坯宽度[mm]" prop="en_wid">
          <el-input v-model="tbProcalcSumDTO.en_wid" placeholder="板坯宽度" @input="(v)=>(tbProcalcSumDTO['en_wid'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="成品厚度[mm]" prop="cc_ST">
          <el-input v-model="tbProcalcSumDTO.cc_ST" placeholder="成品厚度" @input="(v)=>(tbProcalcSumDTO['cc_ST'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="终轧温度[℃]" prop="dischtrgtemp">
          <el-input v-model="tbProcalcSumDTO.dischtrgtemp" placeholder="终轧温度" @input="(v)=>(tbProcalcSumDTO['dischtrgtemp'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item v-if="flag !== 1" label="入口速度[m/s]"  prop="en_spd"> 
          <el-input v-model="tbProcalcSumDTO.en_spd" placeholder="入口速度" @input="(v)=>(tbProcalcSumDTO['en_spd'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="卷取温度[℃]" prop="ct_ex_temp">
          <el-input v-model="tbProcalcSumDTO.ct_ex_temp" placeholder="卷取温度" @input="(v)=>(tbProcalcSumDTO['ct_ex_temp'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 化学元素 -->
    <el-card style="margin: 10px 0">
      <BasicForm :form-list="huaxueList" :form-info="elementDTO" inline></BasicForm>
    </el-card>
    <!-- 任务信息 -->
    <el-card header="任务信息" style="margin: 10px 0">
      <el-form :model="tbProcalcSumDTO" :inline="true">
        <el-form-item label="任务名称" prop="name">
          <el-input v-model.trim="tbProcalcSumDTO.name" placeholder="任务名称"></el-input>
        </el-form-item>
        <el-form-item label="提交人" prop="subPerson">
          <el-input v-model.trim="tbProcalcSumDTO.subPerson" placeholder="提交人"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="note">
          <el-input v-model.trim="tbProcalcSumDTO.note" :rows="5" type="textarea" placeholder="请输入备注"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button v-if="flag !== 1" type="primary" size="small" @click="submit">提交</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card v-if="flag == 1" header="仿真结果"  style="margin: 10px 0">
      <hmi-echarts :x-axis="chart.xAxis" :y-axis="chart.yAxis" :series="chart.series" :grid="chart.grid" _width="100%"></hmi-echarts>
    </el-card>
    <!-- 出水管 -->
    <el-card v-if="flag == 1" header="仿真结果">
      <LCSGuan :temp-switch="layerCooling"></LCSGuan>
    </el-card>
  </div>
</template>

<script>
import BasicForm from "../components/BasicForm.vue";
import LCSGuan from "./LCSGuan.vue";
import { FceParams } from "@/lib/commonVar.js";
import { post } from "@/lib/Util";
import HmiEcharts from "../../components/HmiEcharts.vue";
export default {
  components: { BasicForm, LCSGuan, HmiEcharts },
  props: {
    formInfo: {
      type: Object,
      default: () => {}
    },
    flag: {
      type: Number,
      default: 0 // 0 新建, 1 查看, 2 编辑
    }
  },
  data() {
    return {
      tbProcalcSumDTO: {
        versioncode: 1,
        name: "",
        subPerson: "",
        note: ""
      },
      huaxueList: FceParams,
      steelList: [],
      elementDTO: {},
      layerCooling: {},
      chart: {
        xAxis: [
          {
            type: "category"
          }
        ],
        yAxis: [
          {
            name: "温度(℃)",
            type: "value"
          },
          {
            name: "体积分数",
            nameLocation: "end",
            type: "value"
          }
        ],
        series: [],
        grid: [
          {
            bottom: 40
          }
        ]
      },
      tbCrystalstrCtscV0: {}
    };
  },
  mounted() {
    this.getSteelGrade();
    if (this.flag == 1) {
      this.tbProcalcSumDTO = this.formInfo.tbProcalcSumVO;
      this.elementDTO = this.formInfo.elementVO;
      this.layerCooling = this.formInfo.layerCoolingSetPointVO;
      this.tbCrystalstrCtscV0 = this.formInfo.tbCrystalstrCtscVO;
      this.getLineData();
    } else if (this.flag == 2) {
      this.tbProcalcSumDTO = this.formInfo.tbProcalcSumVO;
      this.elementDTO = this.formInfo.elementVO;
    }
  },
  methods: {
    // 获取曲线
    getLineData() {
      let tbCrystalstrCtscV0 = {
        ferriteVolumeX: {
          name: "铁氧体体积分数",
          type: "line",
          yAxisIndex: 1,
          data: []
        },
        pearliteVolumeX: {
          name: "珠光体体积分数",
          yAxisIndex: 1,
          type: "line",
          data: []
        },
        austeniteVolumeX: {
          name: "奥氏体体积分数",
          yAxisIndex: 1,
          type: "line",
          data: []
        },
        bainiteVolumeX: {
          name: "贝氏体体积分数",
          yAxisIndex: 1,
          type: "line",
          data: []
        },
        martensiteVolumeX: {
          name: "马氏体体积分数",
          yAxisIndex: 1,
          type: "line",
          data: []
        },
        temp: {
          name: "温度",
          type: "line",
          data: []
        }
      };
      for (const key in this.tbCrystalstrCtscV0) {
        if (
          this.tbCrystalstrCtscV0[key] &&
          this.tbCrystalstrCtscV0[key].length
        ) {
          tbCrystalstrCtscV0[key].data = this.tbCrystalstrCtscV0[key].split(
            "&"
          );
          this.chart.series.push(tbCrystalstrCtscV0[key]);
        }
      }
      console.log(this.chart);
    },
    // 查询钢种
    async getSteelGrade() {
      let res = await post("/api/tbChemical/getSteelGrade", {});
      this.steelList = res.data;
    },
    handleSteelChange(val) {
      if (val) {
        let item = this.steelList.filter(item => item.steelGrade == val);
        post(`/api/tbChemical/byIdSelect?id=${item[0].id}`).then(res => {
          this.elementDTO = res.data;
        });
      } else {
        this.$refs.huaRef.resetForm();
      }
    },
    // 提交事件
    submit() {
      this.tbProcalcSumDTO["calcType"] = 4; // 标记这是层冷仿真
      post("/api/tbProcalcSum/layerCoolingSave", {
        tbProcalcSumDTO: this.tbProcalcSumDTO,
        elementDTO: this.elementDTO
      }).then(res => {
        if (res.code == 200) {
          this.$message({
            message: "提交成功",
            type: "success"
          });
        } else {
          this.$message.error(res.message);
        }
        this.$emit("close");
      });
    }
  }
};
</script>

<style>
</style>
